﻿
@{
    ViewData["Title"] = "CreateWireTransfe";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
<style>
    .layui-form-label {
        width: 115px;
    }

    .layui-input {
        width: 85%;
    }

    .layui-textarea {
        width: 85%;
    }
</style>
<script type="text/javascript">
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form', 'upload'], function () {
        var $ = layui.$
            , form = layui.form
            , admin = layui.admin
            , table = layui.table
            , upload = layui.upload
            , parentFrameIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引;

        /**多语言初始化 */
        top.SetFormPageLanguage(layui);

        //$.getJSON("/Console/Roles/GetListJson?userType=1", function (result) {
        //    let plat = result.data;
        //    $('#RoleId').append(new Option(top.lang.pleaseSelect, ""));
        //    plat.forEach(function (v) {
        //        for (var key in top.lang) {
        //            if (top.lang.hasOwnProperty(key)) {
        //                if (key === v.remark) {
        //                    var text = top.lang[key];
        //                    $('#RoleId').append(new Option(text, v.id));
        //                }
        //            }
        //        }
        //    });
        //    layui.form.render("select");
        //});

        //$.getJSON("/Console/Currency/GetListJson?page=0&limit=0&state=1", function (result) {
        //    let plat = result.data;
        //    $('#Currency').append(new Option(top.lang.pleaseSelect, ""));
        //    plat.forEach(function (v) {
        //        $('#Currency').append(new Option(v.currency, v.currency));
        //    });
        //    layui.form.render("select");
        //});

        /* 监听提交 */
        form.on('submit(submit-form)', function (data) {
            //if ($("#Currency").val() == "") {
            //    top.AlertByKey(layui, "enterCurrencyReceipt", 0);
            //    return false;
            //}
            if ($("#Payee").val() == "") {
                top.AlertByKey(layui, "enterPayee", 0);
                return false;
            }
            if ($("#AccountNumber").val() == "") {
                top.AlertByKey(layui, "enterPayeeNumber", 0);
                return false;
            }
            if ($("#PayeeAddress").val() == "") {
                top.AlertByKey(layui, "enterPayeeAddress", 0);
                return false;
            }
            if ($("#Bank").val() == "") {
                top.AlertByKey(layui, "enterReceivingBank", 0);
                return false;
            }
            if ($("#BankAddress").val() == "") {
                top.AlertByKey(layui, "enterBankAddress", 0);
                return false;
            }
            var Minimum = $("#Minimum").val().trim().replace(/,/g, '');
            var Maximum = $("#Maximum").val().trim().replace(/,/g, '');
            if (Minimum == "") {
                top.AlertByKey(layui, "enterMinimum", 0);
                return false;
            } else if (isNaN(Minimum)) {
                top.AlertByKey(layui, "pleaseEnterThanZero", 0);
                return false;
            } else if (Number(Minimum) <= 0) {
                top.AlertByKey(layui, "pleaseEnterThanZero", 0);
                return false;
            }
            //else if (Number(Minimum) % 100 !== 0) {
            //    top.AlertByKey(layui, "pleaseMinEnterOf100", 0);
            //    return false;
            //}
            if (Maximum == "") {
                top.AlertByKey(layui, "enterMaximum", 0);
                return false;
            } else if (isNaN(Maximum)) {
                top.AlertByKey(layui, "pleaseEnterThanZero", 0);
                return false;
            } else if (Number(Maximum) <= 0) {
                top.AlertByKey(layui, "pleaseEnterThanZero", 0);
                return false;
            }
            //else if (Number(Maximum) % 100 !== 0) {
            //    top.AlertByKey(layui, "pleaseMaxEnterOf100", 0);
            //    return false;
            //}
            if (Number(Maximum) <= Number(Minimum)) {
                top.AlertByKey(layui, "maximumOutweighMinimum", 0);
                return false;
            }
            if ($("#Sort").val() == "") {
                top.AlertByKey(layui, "enterSort", 0);
                return false;
            } else if (isNaN($("#Sort").val())) {
                top.AlertByKey(layui, "sortNotIsNumber", 0);
                return false;
            }
            if (data.field.Status == "on") {
                data.field.Status = 1;
            } else {
                data.field.Status = 0;
            }
            data.field.Minimum = Minimum;
            data.field.Maximum = Maximum;
            $.ajax({
                type: "POST",
                url: "/Console/BasicSettings/CreateWireTransfe",
                data: data.field, // 你的formid
                async: true,
                error: function (request) {
                    alert("Connection error");
                },
                beforeSend: function (xhr) {
                    layui.layer.load();
                },
                success: function (data) {
                    var item = eval(data);
                    if (item.code == 0) {
                        /**提示语弹框 */
                        top.ShowMessageByKey(layui, "submitSuccess", 6, 1000, function () {
                            parent.layer.close(parentFrameIndex);
                            parent.wireTransferTable();
                        });
                    } else {
                        /**提示语弹框 */
                        top.AlertByKey(layui, item.msg, 0);
                    }
                    layer.closeAll('loading');
                }
            });
            return false;
        });

        // 监听按钮点击事件
        form.on('submit(upload-button-remove)', function (data) {
            $("#upload-img-Qrcode").attr("src", "/images/noimage.png");
            $("#Qrcode").val("");
            $("#uploadBtnText").text(top.lang.uploadPhoto);
            return false; // 阻止按钮的默认行为
        });

        //上传
        upload.render({
            elem: '#uploadCertificate,#changeOne'
            , url: '/Console/BasicSettings/UploadFile'
            , size: 100
            , done: function (res) {
                $("#Qrcode").val(res.data.src);
                $("#upIcon").addClass('layui-hide');
                $('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.data.src);
            }
        });

        //删除图片
        $('#remove').click(function () {
            $("#upIcon").removeClass('layui-hide');
            $('#uploadDemoView').val('').addClass('layui-hide').find('img').attr('src', '');
            $("#Qrcode").val("");
        });

        $('#view').click(function () {
            var src = $("#certificate").attr("src");
            if (src) {
                previewImg(src);
            }
        });
        function previewImg(src) {
            var imgHtml = "<div style='overflow:auto;display:flex;align-items:center;width:700px;height:700px;justify-content:center;'>"
                + "<img style='width:auto;height:auto;text-align:center;' src='" + src + "' /></div>";
            //弹出层
            layer.open({
                type: 1,
                shade: true,
                shade: [0.4, '#000000'],
                title: false, //不显示标题
                area: ['auto', 'auto'],
                content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
                cancel: function () {

                }
            });
        }

        //// 监听input元素的blur事件
        //document.getElementById('Minimum').addEventListener('blur', function () {
        //    if ($("#Minimum").val() == "") {
        //        top.AlertByKey(layui, "enterMinimum", 0);
        //        return false;
        //    } else if (isNaN($("#Minimum").val())) {
        //        top.AlertByKey(layui, "pleaseMinEnterOf100", 0);
        //        return false;
        //    } else if (Number($("#Minimum").val()) <= 0) {
        //        top.AlertByKey(layui, "pleaseMinEnterOf100", 0);
        //        return false;
        //    } else if (Number($("#Minimum").val()) % 100 !== 0) {
        //        top.AlertByKey(layui, "pleaseMinEnterOf100", 0);
        //        return false;
        //    }
        //});
        //document.getElementById('Maximum').addEventListener('blur', function () {
        //    if ($("#Minimum").val() == "") {
        //        top.AlertByKey(layui, "enterMinimum", 0);
        //        return false;
        //    } else if (isNaN($("#Minimum").val())) {
        //        top.AlertByKey(layui, "pleaseMinEnterOf100", 0);
        //        return false;
        //    } else if (Number($("#Minimum").val()) <= 0) {
        //        top.AlertByKey(layui, "pleaseMinEnterOf100", 0);
        //        return false;
        //    } else if (Number($("#Minimum").val()) % 100 !== 0) {
        //        top.AlertByKey(layui, "pleaseMinEnterOf100", 0);
        //        return false;
        //    }
        //    if ($("#Maximum").val() == "") {
        //        top.AlertByKey(layui, "enterMaximum", 0);
        //        return false;
        //    } else if (isNaN($("#Maximum").val())) {
        //        top.AlertByKey(layui, "pleaseMaxEnterOf100", 0);
        //        return false;
        //    } else if (Number($("#Maximum").val()) <= 0) {
        //        top.AlertByKey(layui, "pleaseMaxEnterOf100", 0);
        //        return false;
        //    } else if (Number($("#Maximum").val()) % 100 !== 0) {
        //        top.AlertByKey(layui, "pleaseMaxEnterOf100", 0);
        //        return false;
        //    }
        //    if (Number($("#Maximum").val()) <= Number($("#Minimum").val())) {
        //        top.AlertByKey(layui, "maximumOutweighMinimum", 0);
        //        return false;
        //    }
        //});
        //光标离开输入的金额四舍五入并保留4位小数
        $("#Minimum").blur(function () {
            var obj = this.value;
            var mnyReg = /^([1-9][0-9]*|(([0]\.[0-9]{0,2}[1-9]\d*|[1-9][0-9]*\.\d*)))$/;//根据需求修改
            if (!(mnyReg.test(obj))) {
                top.AlertByKey(layui, "enterNotIsNumber", 0);
                return;
            }
            var n = 2; //保留得小数位
            obj = parseFloat(obj).toFixed(n);
            var left = obj.split(".")[0].split("").reverse();
            var right = obj.split(".")[1];
            var total = new Array();
            for (i = 0; i < left.length; i++) {
                total.push(left[i]);
                if ((i + 1) % 3 == 0 && (i + 1) != left.length) {
                    total.push(",");
                }
            }
            $("#Minimum").val(total.reverse().join("") + "." + right);
            if ($("#Maximum").val() != "") {
                var Minimum = $("#Minimum").val().trim().replace(/,/g, '');
                var Maximum = $("#Maximum").val().trim().replace(/,/g, '');
                if (Number(Maximum) <= Number(Minimum)) {
                    top.AlertByKey(layui, "maximumOutweighMinimum", 0);
                    return false;
                }
            }
        });

        //光标进入，去除金额千分位，并去除小数后面多余的0
        $("#Minimum").focus(function () {
            var oldMny = this.value.replace(/,/g, '');
            if (oldMny.indexOf(".") > 0) {
                oldMny = oldMny.replace(/0+?$/, "");//去除尾部多余的0
                oldMny = oldMny.replace(/[.]$/, "");//如果最后一位是.则去掉
            }
            this.value = oldMny;
        });

        //光标离开输入的金额四舍五入并保留4位小数
        $("#Maximum").blur(function () {
            var obj = this.value;
            var mnyReg = /^([1-9][0-9]*|(([0]\.[0-9]{0,2}[1-9]\d*|[1-9][0-9]*\.\d*)))$/;//根据需求修改
            if (!(mnyReg.test(obj))) {
                top.AlertByKey(layui, "enterNotIsNumber", 0);
                return;
            }
            var n = 2; //保留得小数位
            obj = parseFloat(obj).toFixed(n);
            var left = obj.split(".")[0].split("").reverse();
            var right = obj.split(".")[1];
            var total = new Array();
            for (i = 0; i < left.length; i++) {
                total.push(left[i]);
                if ((i + 1) % 3 == 0 && (i + 1) != left.length) {
                    total.push(",");
                }
            }
            $("#Maximum").val(total.reverse().join("") + "." + right);

            var Minimum = $("#Minimum").val().trim().replace(/,/g, '');
            var Maximum = $("#Maximum").val().trim().replace(/,/g, '');
            if (Number(Maximum) <= Number(Minimum)) {
                top.AlertByKey(layui, "maximumOutweighMinimum", 0);
                return false;
            }
        });

        //光标进入，去除金额千分位，并去除小数后面多余的0
        $("#Maximum").focus(function () {
            var oldMny = this.value.replace(/,/g, '');
            if (oldMny.indexOf(".") > 0) {
                oldMny = oldMny.replace(/0+?$/, "");//去除尾部多余的0
                oldMny = oldMny.replace(/[.]$/, "");//如果最后一位是.则去掉
            }
            this.value = oldMny;
        });
    });
</script>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" action="" lay-filter="component-form-element">
                    <div class="layui-row layui-col-space10 layui-form-item">
                        @*<div class="layui-col-xs5">
                                <label class="layui-form-label" lay-event="currencyReceipt">收款货币</label>
                                <div class="layui-input-block">
                                    <select name="Currency" id="Currency">
                                    </select>
                                </div>
                            </div>*@
                        <div class="layui-col-xs5">
                            <label class="layui-form-label" lay-event="bankAccountName">银行户名</label>
                            <div class="layui-input-block">
                                <input type="text" name="Payee" id="Payee" placeholder="enterBankAccountName" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs5">
                            <label class="layui-form-label" lay-event="payeeNumber">收款账号</label>
                            <div class="layui-input-block">
                                <input type="text" name="AccountNumber" id="AccountNumber" placeholder="enterPayeeNumber" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs5">
                            <label class="layui-form-label" lay-event="payeeAddress">联邦清算号</label>
                            <div class="layui-input-block">
                                <input type="text" name="PayeeAddress" id="PayeeAddress" placeholder="enterPayeeAddress" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs5">
                            <label class="layui-form-label" lay-event="receivingBank">收款银行</label>
                            <div class="layui-input-block">
                                <input type="text" name="Bank" id="Bank" placeholder="enterReceivingBank" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label" lay-event="bankAddress">银行地址</label>
                            <div class="layui-input-block">
                                <input type="text" name="BankAddress" id="BankAddress" placeholder="enterBankAddress" class="layui-input">
                            </div>
                        </div>
                        @*<div class="layui-col-xs5">
                                <label class="layui-form-label layui-required" lay-event="role">角色</label>
                                <div class="layui-input-block">
                                    <select name="RoleId" id="RoleId">
                                    </select>
                                </div>
                            </div>*@
                        <div class="layui-form-item">
                            <label class="layui-form-label" lay-event="swiftcode">SWIFT</label>
                            <div class="layui-input-block">
                                <input type="text" name="Swiftcode" id="Swiftcode" placeholder="enterSwiftcode" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs5">
                            <label class="layui-form-label" lay-event="minimum">单笔最低入金金额</label>
                            <div class="layui-input-block">
                                <input type="text" name="Minimum" id="Minimum" placeholder="enterMinimum" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs5">
                            <label class="layui-form-label" lay-event="maximum">单笔最高入金金额</label>
                            <div class="layui-input-block">
                                <input type="text" name="Maximum" id="Maximum" placeholder="enterMaximum" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs5">
                            <label class="layui-form-label" lay-event="sort">排序</label>
                            <div class="layui-input-block">
                                <input type="number" name="Sort" id="Sort" value="@ViewBag.Sort" placeholder="enterNotIsNumber" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-xs5">
                            <label class="layui-form-label" lay-event="state">状态</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="Status" id="Status" lay-skin="switch" lay-text="ON|OFF" checked="checked">
                            </div>
                        </div>
                        <div class="layui-form-item" style="display:none;">
                            <label class="layui-form-label" lay-event="qrcode">收款二维码</label>
                            <div class="layui-upload-drag" id="uploadCertificate">
                                <i id="upIcon" class="layui-icon"></i>
                                <div class="layui-hide" id="uploadDemoView">
                                    <img src="" style="max-width: 120px" id="certificate">
                                    <input type="hidden" name="Qrcode" id="Qrcode" class="layui-input">
                                </div>
                            </div>
                            <button type="button" class="layui-btn" id="changeOne">换一张</button>
                            <button type="button" class="layui-btn layui-btn-danger" id="remove">移除</button>
                            <button type="button" class="layui-btn layui-btn-primary" id="view" lay-event="view">查看</button>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label" lay-event="remark">备注</label>
                            <div class="layui-input-block">
                                <textarea name="Remark" id="Remark" placeholder="enterTypeRemark" class="layui-textarea"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button class="layui-btn" lay-submit="" lay-filter="submit-form">立即提交</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
